unit Settings;

interface

uses
  GlobalRecordsAndEnums;

type
  TSettings = class
    public
      // User adjustable from Edit -> Settings -> tab Settings.
      UseFees: Boolean;
      SalesTax: Double;
      BrokersFee: Double;

      // Not user adjustable
      AppLeft: Integer;
      AppTop: Integer;
      AppWidth: Integer;
      AppHeight: Integer;
      Columns: Array [0..10] of EColumn;
      SortColumn: EColumn;
      SortDirection: Boolean;
      ItemsSortColumn: Integer;
      ItemsSortDirection: Boolean;
      ItemsFilter: Array [-1..11] of Boolean;
      FilterAmarr: Boolean;
      FilterCaldari: Boolean;
      FilterGallente: Boolean;
      FilterMinmatar: Boolean;
      ImportPricesDefaultSettingIndex: Integer;
      ShoppingItemsSortColumn: Integer;
      ShoppingItemsSortDirection: Boolean;
      ShoppingBuySortColumn: Integer;
      ShoppingBuySortDirection: Boolean;
      ShoppingManufactureSortColumn: Integer;
      ShoppingManufactureSortDirection: Boolean;
      SettingsActiveTab: Integer;
      ResultFilterItems: Boolean;
      ResultsConfigurationSortColumn: Integer;
      ResultsConfigurationSortDirection: Boolean;

      ImportPricesRegions0: Double;
      ImportPricesRegions1: Double;
      ImportPricesRegions2: Double;
      SettingsAPIUsername: String[100];
      SettingsAPIKey: String[100];

      SortColumn2: EColumn;
      SortDirection2: Boolean;
      SortColumn3: EColumn;
      SortDirection3: Boolean;
      ItemsSortColumn2: Integer;
      ItemsSortDirection2: Boolean;
      ItemsSortColumn3: Integer;
      ItemsSortDirection3: Boolean;

      constructor Create;
      procedure Load(settings: SSettings); overload;
      procedure Load(settings: SSettings_v043); overload;
      procedure Load(settings: SSettings_v044); overload;
      function Save: SSettings_v044;
  end;

implementation

constructor TSettings.Create;
var
  i: Integer;
begin
  UseFees := true;
  SalesTax := 0.01;
  BrokersFee := 0.01;

  AppLeft := 100;
  AppTop := 100;
  AppWidth := 813;
  AppHeight := 671;
  for i := 0 to 9 do begin
    Columns[i] := COL_None;
  end;
  Columns[0] := COL_Name;
  Columns[1] := COL_InventionProfit;
  SortColumn := COL_Name;
  SortDirection := true;
  ItemsSortColumn := 1;
  ItemsSortDirection := true;
  for i := -1 to 11 do begin
    ItemsFilter[i] := true;
  end;
  FilterAmarr := true;
  FilterCaldari := true;
  FilterGallente := true;
  FilterMinmatar := true;
  ImportPricesDefaultSettingIndex := 7;
  ShoppingItemsSortColumn := 1;
  ShoppingItemsSortDirection := true;
  ShoppingBuySortColumn := 1;
  ShoppingBuySortDirection := true;
  ShoppingManufactureSortColumn := 1;
  ShoppingManufactureSortDirection := true;
  SettingsActiveTab := 0;
  ResultFilterItems := false;
  ResultsConfigurationSortColumn := 0;
  ResultsConfigurationSortDirection := true;

  ImportPricesRegions0 := 0;
  ImportPricesRegions1 := 0;
  ImportPricesRegions2 := 0;
  SettingsAPIUsername := '';
  SettingsAPIKey := '';

  SortColumn2 := COL_Name;
  SortDirection2 := true;
  SortColumn3 := COL_Name;
  SortDirection3 := true;

  ItemsSortColumn2 := 2;
  ItemsSortDirection2 := true;
  ItemsSortColumn3 := 3;
  ItemsSortDirection3 := true;
end;

procedure TSettings.Load(settings: SSettings);
var
  i: Integer;
begin
  UseFees := settings.UseFees;
  SalesTax := settings.SalesTax;
  BrokersFee := settings.BrokersFee;

  AppLeft := settings.AppLeft;
  AppTop := settings.AppTop;
  AppWidth := settings.AppWidth;
  AppHeight := settings.AppHeight;
  for i := 0 to 9 do begin
    Columns[i] := settings.Columns[i];
  end;
  SortColumn := settings.SortColumn;
  SortDirection := settings.SortDirection;
  ItemsSortColumn := settings.ItemsSortColumn;
  ItemsSortDirection := settings.ItemsSortDirection;
  for i := -1 to 11 do begin
    ItemsFilter[i] := settings.ItemsFilter[i];
  end;
  FilterAmarr := settings.FilterAmarr;
  FilterCaldari := settings.FilterCaldari;
  FilterGallente := settings.FilterGallente;
  FilterMinmatar := settings.FilterMinmatar;
  ImportPricesDefaultSettingIndex := settings.ImportPricesDefaultSettingIndex;
  ShoppingItemsSortColumn := settings.ShoppingItemsSortColumn;
  ShoppingItemsSortDirection := settings.ShoppingItemsSortDirection;
  ShoppingBuySortColumn := settings.ShoppingBuySortColumn;
  ShoppingBuySortDirection := settings.ShoppingBuySortDirection;
  ShoppingManufactureSortColumn := settings.ShoppingManufactureSortColumn;
  ShoppingManufactureSortDirection := settings.ShoppingManufactureSortDirection;
  SettingsActiveTab := settings.SettingsActiveTab;
  ResultFilterItems := settings.ResultFilterItems;
  ResultsConfigurationSortColumn := settings.ResultsConfigurationSortColumn;
  ResultsConfigurationSortDirection := settings.ResultsConfigurationSortDirection;
end;

procedure TSettings.Load(settings: SSettings_v043);
var
  i: Integer;
begin
  UseFees := settings.UseFees;
  SalesTax := settings.SalesTax;
  BrokersFee := settings.BrokersFee;

  AppLeft := settings.AppLeft;
  AppTop := settings.AppTop;
  AppWidth := settings.AppWidth;
  AppHeight := settings.AppHeight;
  for i := 0 to 10 do begin
    Columns[i] := settings.Columns[i];
  end;
  SortColumn := settings.SortColumn;
  SortDirection := settings.SortDirection;
  ItemsSortColumn := settings.ItemsSortColumn;
  ItemsSortDirection := settings.ItemsSortDirection;
  for i := -1 to 11 do begin
    ItemsFilter[i] := settings.ItemsFilter[i];
  end;
  FilterAmarr := settings.FilterAmarr;
  FilterCaldari := settings.FilterCaldari;
  FilterGallente := settings.FilterGallente;
  FilterMinmatar := settings.FilterMinmatar;
  ImportPricesDefaultSettingIndex := settings.ImportPricesDefaultSettingIndex;
  ShoppingItemsSortColumn := settings.ShoppingItemsSortColumn;
  ShoppingItemsSortDirection := settings.ShoppingItemsSortDirection;
  ShoppingBuySortColumn := settings.ShoppingBuySortColumn;
  ShoppingBuySortDirection := settings.ShoppingBuySortDirection;
  ShoppingManufactureSortColumn := settings.ShoppingManufactureSortColumn;
  ShoppingManufactureSortDirection := settings.ShoppingManufactureSortDirection;
  SettingsActiveTab := settings.SettingsActiveTab;
  ResultFilterItems := settings.ResultFilterItems;
  ResultsConfigurationSortColumn := settings.ResultsConfigurationSortColumn;
  ResultsConfigurationSortDirection := settings.ResultsConfigurationSortDirection;

  ImportPricesRegions0 := settings.ImportPricesRegions0;
  ImportPricesRegions1 := settings.ImportPricesRegions1;
  ImportPricesRegions2 := settings.ImportPricesRegions2;
  SettingsAPIUsername := settings.SettingsAPIUsername;
  SettingsAPIKey := settings.SettingsAPIKey;
end;

procedure TSettings.Load(settings: SSettings_v044);
var
  i: Integer;
begin
  UseFees := settings.UseFees;
  SalesTax := settings.SalesTax;
  BrokersFee := settings.BrokersFee;

  AppLeft := settings.AppLeft;
  AppTop := settings.AppTop;
  AppWidth := settings.AppWidth;
  AppHeight := settings.AppHeight;
  for i := 0 to 10 do begin
    Columns[i] := settings.Columns[i];
  end;
  SortColumn := settings.SortColumn;
  SortDirection := settings.SortDirection;
  ItemsSortColumn := settings.ItemsSortColumn;
  ItemsSortDirection := settings.ItemsSortDirection;
  for i := -1 to 11 do begin
    ItemsFilter[i] := settings.ItemsFilter[i];
  end;
  FilterAmarr := settings.FilterAmarr;
  FilterCaldari := settings.FilterCaldari;
  FilterGallente := settings.FilterGallente;
  FilterMinmatar := settings.FilterMinmatar;
  ImportPricesDefaultSettingIndex := settings.ImportPricesDefaultSettingIndex;
  ShoppingItemsSortColumn := settings.ShoppingItemsSortColumn;
  ShoppingItemsSortDirection := settings.ShoppingItemsSortDirection;
  ShoppingBuySortColumn := settings.ShoppingBuySortColumn;
  ShoppingBuySortDirection := settings.ShoppingBuySortDirection;
  ShoppingManufactureSortColumn := settings.ShoppingManufactureSortColumn;
  ShoppingManufactureSortDirection := settings.ShoppingManufactureSortDirection;
  SettingsActiveTab := settings.SettingsActiveTab;
  ResultFilterItems := settings.ResultFilterItems;
  ResultsConfigurationSortColumn := settings.ResultsConfigurationSortColumn;
  ResultsConfigurationSortDirection := settings.ResultsConfigurationSortDirection;

  ImportPricesRegions0 := settings.ImportPricesRegions0;
  ImportPricesRegions1 := settings.ImportPricesRegions1;
  ImportPricesRegions2 := settings.ImportPricesRegions2;
  SettingsAPIUsername := settings.SettingsAPIUsername;
  SettingsAPIKey := settings.SettingsAPIKey;

  SortColumn2 := settings.SortColumn2;
  SortDirection2 := settings.SortDirection2;
  SortColumn3 := settings.SortColumn3;
  SortDirection3 := settings.SortDirection3;
  ItemsSortColumn2 := settings.ItemsSortColumn2;
  ItemsSortDirection2 := settings.ItemsSortDirection2;
  ItemsSortColumn3 := settings.ItemsSortColumn3;
  ItemsSortDirection3 := settings.ItemsSortDirection3;
end;

function TSettings.Save: SSettings_v044;
var
  i: Integer;
begin
  result.UseFees := UseFees;
  result.SalesTax := SalesTax;
  result.BrokersFee := BrokersFee;

  result.AppLeft := AppLeft;
  result.AppTop := AppTop;
  result.AppWidth := AppWidth;
  result.AppHeight := AppHeight;
  for i := 0 to 10 do begin
    result.Columns[i] := Columns[i];
  end;
  result.SortColumn := SortColumn;
  result.SortDirection := SortDirection;
  result.ItemsSortColumn := ItemsSortColumn;
  result.ItemsSortDirection := ItemsSortDirection;
  for i := -1 to 11 do begin
    result.ItemsFilter[i] := ItemsFilter[i];
  end;
  result.FilterAmarr := FilterAmarr;
  result.FilterCaldari := FilterCaldari;
  result.FilterGallente := FilterGallente;
  result.FilterMinmatar := FilterMinmatar;
  result.ImportPricesDefaultSettingIndex := ImportPricesDefaultSettingIndex;
  result.ShoppingItemsSortColumn := ShoppingItemsSortColumn;
  result.ShoppingItemsSortDirection := ShoppingItemsSortDirection;
  result.ShoppingBuySortColumn := ShoppingBuySortColumn;
  result.ShoppingBuySortDirection := ShoppingBuySortDirection;
  result.ShoppingManufactureSortColumn := ShoppingManufactureSortColumn;
  result.ShoppingManufactureSortDirection := ShoppingManufactureSortDirection;
  result.SettingsActiveTab := SettingsActiveTab;
  result.ResultFilterItems := ResultFilterItems;
  result.ResultsConfigurationSortColumn := ResultsConfigurationSortColumn;
  result.ResultsConfigurationSortDirection := ResultsConfigurationSortDirection;

  result.ImportPricesRegions0 := ImportPricesRegions0;
  result.ImportPricesRegions1 := ImportPricesRegions1;
  result.ImportPricesRegions2 := ImportPricesRegions2;
  result.SettingsAPIUsername := SettingsAPIUsername;
  result.SettingsAPIKey := SettingsAPIKey;

  result.SortColumn2 := SortColumn2;
  result.SortDirection2 := SortDirection2;
  result.SortColumn3 := SortColumn3;
  result.SortDirection3 := SortDirection3;
  result.ItemsSortColumn2 := ItemsSortColumn2;
  result.ItemsSortDirection2 := ItemsSortDirection2;
  result.ItemsSortColumn3 := ItemsSortColumn3;
  result.ItemsSortDirection3 := ItemsSortDirection3;
end;

end.
